<?php if(isset($updated) && $updated == true){?>
<p><?php echo $message;?></p>
<script language="javascript">
$(document).ready(function() {
	setTimeout(function(){parent.$.fancybox.close()}, 1000);
});
</script>
<?php } elseif(!empty($timesheet)) {?>
<h1>Edit Timesheet</h1>
<?php 
	$ts = $timesheet[0];
	$regular_hours = 8;
	$overtime = $extra_timesheet->overtime_hours;
	$undertime = "00:00:00";
	if(isset($ts->hours) && ($ts->hours > $regular_hours)){
		$overtime = DateUtils::decimal_to_time($ts->hours - $regular_hours);
	} else if ((isset($ts->hours) && ($ts->hours < $regular_hours))) {
		//$undertime = $ts->undertime;
		//if($undertime == null || $undertime == "00:00:00"){
			$undertime = DateUtils::decimal_to_time($regular_hours - $ts->hours);	
		//}
	}

	$night_diff = $extra_timesheet->night_differential;
	
	if(isset($rest_day[0])) {
		$rest = DateUtils::theSameDay($extra_timesheet->date, $rest_day[0]->day);
	}
	$class = isset($rest)?'rest_day':'';
	
?>
<fieldset>
<legend>Details</legend>
<?php echo form_open('timesheet/update');?>
<table width="100%">
	<tr>
		<td align="left">
			<table cellspacing="0" cellpadding="4" width="500" >
			<tr>
				<td>Date</td>
				<td class="native_bold <?php echo $class?>"><?php echo $extra_timesheet->date;?></td>
			</tr>
			<tr>
				<td>Time In:</td>
				<td><input type="text" name="time_in" value="<?php echo $extra_timesheet->time_in?>"></td>
			</tr>
			<tr>
				<td>Time Out:</td>
				<td><input type="text" name="time_out" value="<?php echo $extra_timesheet->time_out?>"></td>
			</tr>
			<tr>
				<td>Late:</td>
				<td><input type="text" name="late" value="<?php echo $ts->late?>"></td>
			</tr>
			<!--<tr>
				<td>Earlier:</td>
				<td><input type="text" name="earlier" value="<?php echo $ts->earlier?>"></td>
			</tr>  -->
			<tr>
				<td>Overtime:</td>
				<td><input type="text" name="overtime" value="<?php echo $overtime?>"></td> 
			</tr>
			<tr>
				<td>Approved Overtime:</td>
				<td><input type="text" name="approved_overtime"  value="<?php echo $ts->approved_overtime?>"></td>
			</tr>
			<tr>
				<td>Undertime:</td>
				<td><input type="text" name="undertime" value="<?php echo $undertime?>"></td> 
			</tr>
			<tr>
				<td>Approved Undertime:</td>
				<td><input type="text" name="approved_undertime"  value="<?php echo $ts->approved_undertime?>"></td>
			</tr>
			<tr>
				<td>Night Differential:</td>
				<td><input type="text" name="night_differential" value="<?php echo $night_diff?>"></td>
			</tr>
			<tr>
				<td>Approved Night Differential:</td>
				<td><input type="text" name="approved_night_differential" value="<?php echo $ts->approved_night_differential?>"></td>
			</tr>
			<tr>
				<td>Remarks:</td>
				<td>
					<select name="remarks" id="remarks">
						<option value="1">Absent</option>
						<option value="2">Leave with pay</option>
						<option value="3">Leave w/o pay</option>
						<option value="4">Day off</option>
						<option value="5">Wrong Card</option>
						<option value="6">Adjusted</option>
						<option value="7">Present</option>
					</select>
				</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td><input type="submit" value="Update"></td>
			</tr>
			
			</table>
			<?php echo form_hidden("id",$ts->id);?>
			<?php echo form_hidden("date",$extra_timesheet->date);?>	
			<?php echo form_close();?>	
		</td>
		<td valign="top">
			<table cellspacing="0" cellpadding="4" width="200" style="background-color: #ccc;">
			<tr>
				<td class="native_bold" colspan="2">BIOMETRIC ORIGINAL DATA</td>
			</tr>
			<tr>
				<td width="80">Time In:</td>
				<td><?php echo substr($ts->bio_time_in, 11)?></td>
			</tr>
			<tr>
				<td>Time Out:</td>
				<td><?php echo substr($ts->bio_time_out,11)?></td>
			</tr>
			<tr>
				<td>Remarks:</td>
				<td id="bio_remarks"><?php echo $ts->bio_remarks?></td>
			</tr>
			<tr>
				<td>Late:</td>
				<td><?php echo $ts->late?></td>
			</tr>
			
			<tr>
				<td>Undertime:</td>
				<td><?php echo $ts->bio_undertime?></td>
			</tr>
			</table>
		</td>
	</tr>
</table>

</fieldset>
<script language="javascript">
$(document).ready(function() {
	var msg = "<?php echo $message;?>";
	$("select#remarks").val("<?php echo $ts->remarks?>");
	label = $("select#remarks option[value='<?php echo $ts->bio_remarks?>']").text();
	$("td#bio_remarks").text(label);
} );
</script>

<?php } ?>